// pages/detail/strategy_detail.js
//var postsData = require('../../data/post-data.js')
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    clicked: -1,
    clickede: -1,
    clickedes: -1,
    clickedees: -1,
    chooseradio:'0',
    afferent: '',
    mobile: '',
    area: '',
    radvalue: '',
    radname: '',
    main_room: "3室",
    main_tin: "2厅",
    main_wei: "2卫",
    main_yang: "3阳台",
    houstyle: '3223',
    room: 3,
    tin: 2,
    wei: 2,
    yan: 3,
    city:'',
    cityid: '',
    proviceid: '',
    items: [
      {value: '1室',datan: 1 },
      {value: '2室',datan: 2},
      {value: '3室',datan: 3},
      {value: '4室',datan: 4}],
    items1: [
      {value: '1厅',datin: 1},
      {value: '2厅',datin: 2},
      {value: '3厅',datin: 3},
      {value: '4厅',datin: 4}],
    items2: [
      {value: '1卫',datwi: 1},
      {value: '2卫', datwi: 2},
      {value: '3卫',datwi: 3},
      {value: '4卫',datwi: 4}],
    items3: [
      {value: '1阳台',datyt: 1 },
      {value: '2阳台', datyt: 2},
      {value: '3阳台',datyt: 3},
      {value: '4阳台',datyt: 4}],
    choose: [
      {name: '新房装修', value: 1, checked: 'true', },
      {name: '旧房装修',value: 3}],
    hidden: false,
    colist: [
      { name: '人工费',  price: 200},
      {name: '材料费',price: 300},
      {name: '设计费',price: 100},
      {name: '质检费',price: 100 }],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    //var postData = postsData.poststrategy[id];

    console.log(this.data)
  },
  //显示蒙版
  chooroom: function () {
    var that = this;
    this.setData({
      showModal: true,
      Modalcontent: true
    })
  },
  //房屋类型弹框内容点击选择
  choose_btn: function (e) {
    var that = this;
    var room = e.target.dataset.room
    var tin = that.data.tin
    var wei = that.data.wei
    var yan = that.data.yan
    var housty = +room + '' + tin + '' + wei + '' + yan + ''

    var index = parseInt(e.currentTarget.id);
    var value = that.data.items[index].value;
    if (this.data.clicked == e.currentTarget.id) {
      this.setData({
        clickId: +1,
      })
      return;
    }
    that.setData({
      clicked: e.currentTarget.id,
      main_room: value,
      room: room,
      houstyle: housty
    })
    console.log(e)
  },
  choose_tin: function (e) {
    var that = this;
    var index = parseInt(e.currentTarget.id);
    var value = that.data.items1[index].value;
    var room = that.data.room
    var tin = e.target.dataset.tin
    var wei = that.data.wei
    var yan = that.data.yan
    var housty = +room + '' + tin + '' + wei + '' + yan + ''
    if (this.data.clickede == e.currentTarget.id) {
      this.setData({
        clickIde: +1,
      })
      return;
    }
    that.setData({
      clickede: e.currentTarget.id,
      main_tin: value,
      tin: tin,
      houstyle: housty
    })
    console.log(value)
  },

  choose_wei: function (e) {
    var that = this;
    var index = parseInt(e.currentTarget.id);
    var value = that.data.items2[index].value;
    var room = that.data.room
    var tin = that.data.tin
    var wei = e.target.dataset.wei
    var yan = that.data.yan
    var housty = +room + '' + tin + '' + wei + '' + yan + ''
    if (this.data.clickedes == e.currentTarget.id) {
      this.setData({
        clickIdes: +1,
      })
      return;
    }
    that.setData({
      clickedes: e.currentTarget.id,
      main_wei: value,
      wei: wei,
      houstyle: housty
    })
    console.log(value)
  },

  choose_sun: function (e) {
    var that = this;
    var index = parseInt(e.currentTarget.id);
    var value = that.data.items3[index].value;
    var room = that.data.room
    var tin = that.data.tin
    var wei = that.data.wei
    var yan = e.target.dataset.tty
    var housty = +room + '' + tin + '' + wei + '' + yan + ''
    if (this.data.clickedese == e.currentTarget.id) {
      this.setData({
        clickIdese: +1,
      })
      return;
    }
    that.setData({
      clickedese: e.currentTarget.id,
      main_yang: value,
      yan: yan,
      houstyle: housty
    })
    console.log(value)
  },
  //面积，装修方式，手机号码获取
  radioChange: function (e) {
    var values = e.detail.value
    var radname = e.detail.name
    this.setData({
      radvalue: values
    })
    console.log(values)
  },
  givearea: function (e) {
    var value = e.detail.value
    this.setData({
      area: value
    })
  },
  givetele: function (e) {
    var value = e.detail.value
    this.setData({
      mobile: value
    })
  },

  //弹框隐藏
  confirm: function () {
    var that = this;
    this.setData({
      showModal: false,
      Modalcontent: false
    })
  },
  cancle: function () {
    var that = this;
    this.setData({
      showModal: false,
      Modalcontent: false
    })
  },

  radioChange: function (e) {
    var values = e.currentTarget.dataset.id
    var name = e.currentTarget.dataset.name
    console.log(e)
    if (this.data.clickedes == e.currentTarget.id) {
      this.setData({
        chooseradio: +1,
      })
      return;
    }
    this.setData({
      radvalue: values,
      chooseradio: e.currentTarget.id,
    })
  },
  givearea: function (e) {
    var value = e.detail.value
    this.setData({
      area: value
    })
  },
  givetele: function (e) {
    var value = e.detail.value
    this.setData({
      mobile: value
    })
  },
  skipsrsult: function (e) {
    var arr = []
    //var city = this.data.afferent
    var alea = this.data.area
    var mobile = this.data.mobile
    var radios = this.data.radvalue
    var mainroom = this.data.main_room
    var ting = this.data.main_tin
    var wei = this.data.main_wei
    var yang = this.data.main_yang
    var huxing = mainroom + '' + ting + '' + wei + '' + yang + ''
    var houstyle = this.data.houstyle
    var cityid = this.data.cityid
    var proviceid = this.data.proviceid
    var city = this.data.city
    arr.push({
      'alea': alea
    }, {
        'mobile': mobile
      }, {
        'radios': radios
      }, {
        'mainroom': mainroom
      }, {
        'ting': ting
      }, {
        'wei': wei
      }, {
        'yang': yang
      })
    if (alea == '') {
      wx.showToast({
        title: '面积不能为空',
        icon: 'false',
        duration: 2000
      })
    } else if (radios == '') {
      wx.showToast({
        title: '装修类型未选择',
        icon: 'false',
        duration: 2000
      })
    } else if (mobile == '') {
      wx.showToast({
        title: '电话号码能为空',
        icon: 'false',
        duration: 2000
      })
    } else {
      // this.getevaluate()
      wx.request({
        //url: app.apiUrl("c=zhaobiao/index&a=submit_estimate"),
        url: 'http://www.newx.com/api/weixinapp/?c=zhaobiao/index&a=submit_estimate',
        data: {
          phone: mobile,
          acreage: alea,
          house_type: houstyle,
          decorate_type: radios,
          province: proviceid,
          city: cityid
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        method: 'POST',
        success: function (res) {
          console.log(res.data)
          var id = 1
          wx.navigateTo({
            url: '../free/quote_result?data=' + [id, alea, radios, mainroom, ting, wei, yang, city, mobile,huxing]
          })
        }
      })
      // var id = 1
      // wx.navigateTo({
      //   url: '../free/quote_result?data=' + [id, alea, radios, mainroom, ting, wei, yang, city, mobile]
      // })
    }
    console.log(arr)
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */


  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    //var value = wx.getStorageSync('concent');
    //console.log('这个value', value)
    // this.setData({
    //   afferent: value
    // })
  },
  choosecity: function (e) {
    var id = 6
    var city = this.data.afferent
    wx.navigateTo({
      url: 'custom/cucity',
    })
  },

})